// JavaScript Document
//设置视频的src地址
 

window.setsrc=function (s,i){
	try{
 oPlayer.player().src=s.replace(/#/g,'%23');
 oPlayer.player().play();
 if(typeof i !=='undefined' ){
 VideoArray.__$setCurrent$__(i);}
	}catch(e){ console.warn( e ) }
 
		//window.subtitle=Object.create(window._subtitle);
		//window. subtitle= (window._subtitle).__$clone$__();
		
/*		window.subtitle =
		[
{"s":38000,"e":48000,"lyric":"骚货骚得够可以的了哈@@@@@@哈哈"}		 
,{"s":8000,"e":12000,"lyric":"33333333在玩弄三在333"}	
,{"s":8100,"e":11900,"lyric":"test33"}	
,{"s":12000,"e":16000,"lyric":"thfg@@@hfthf"}	
,{"s":16000,"e":20000,"lyric":"htfhthfzh一下眄睛"}	
,{"s":20000,"e":24000,"lyric":"下下上盯要醇正二本"}	
,{"s":24000,"e":28000,"lyric":"唇形二在城无奇不有"}	
 
,{"s":28870,"e":38000,"lyric":"思绪在风中摇曳"}

 	
];*/
		
		tre.trace(s,'green',20)	
		    if(window.runPlugLyric){
			//运行歌词字幕			 
			tre.trace('runPlugLyric()','green',20)	 
            runPlugLyric();
			window.initPlugLyric();
			}
			//ctrler.forbidAutoLoadLyric 禁止自动加载歌词

			//重新加载歌词，设置播放时间为开始播放  
			window.setTimeout(
			window.setItemEmpty , 2000)
			
			 
			 if(window.forbidAutoLoadLyric!==true){
			window.setTimeout(
			window.getLyrJSON , 2000)
			 }
			 
}
//元素显示隐藏切换
window.jstoggle=function(el){
    if(el.style.display!='none'){
	el.style.display='none';    	
	}else{
	el.style.display='block';	
    }	
}

//循环世界，这个函数会不停的运行 一秒钟最多可以运行60次
//作用：当当前视频播放结束时 ，用window.randPlay();改变视频地址
function loopworld(){
 var diff =oPlayer.player().duration -oPlayer.player().currentTime 
 if(diff<1){
	 
	 if(loopworld.ended !== true
	 
	 ){
	   //if语句内的内容只运行一次
	   //播放结束 重载当前页
	   //tre.trace('ended','green',20)	 
	   window.setTimeout(function(){window.loopworld.ended = false;
	   window.oLyric.itemId = new Array();
	   console.warn('清空歌词')
	   },1500)
	   if( window.loopworld.Singleloop==false ){
	   //window.location.reload();
	     window.randPlay();
		 window.setItemEmpty();
		 console.warn('随机播放')
	   }
	 }
	 
	 //小于1秒播放就结束了 于是运行 window.randPlay(); 并设置ended = true;就不会再运行了，
	 //1500毫秒后设置为假，所以达到结束条件会再次运行
     window.loopworld.ended = true;
		 
 }
  //console.log(diff);
 window.requestAnimationFrame(loopworld)
}




//从a标签的title属性中得到所有视频的地址
function __getVideoArray(){
	var retarr=new Array(); 
	
	//lis 是取有的li集合
	var lis=document.getElementById('videolist').childNodes;
			 
	for($i=0 ,len=lis.length ;$i<len;$i++){
		//测试当前元素是不是li元素  /li|LI/.test(lis[$i].nodeName) 
		if(/li|LI/.test(lis[$i].nodeName) ){
			
			//获取 a 标签的title属性
			if(lis[$i].childNodes[0].hasAttribute('title')){
			retarr[$i]=lis[$i].childNodes[0].title.replace(/#/g,'%23');	
			}   
		}
	}

return retarr;

//document.getElementById('videolist').childNodes[1].childNodes[0].title
}


//随机选择一个视频播放功能
/*window.randPlay=function( ){
	 var r = window.aList.__$rselect$__(window.VideoArrayShuffle);
	  setsrc(r[0]);
	 console.log(window.aList.length)
	 console.log(r[0])
	 window.tre.traceOne(window.aList.length+','+r[0],false)
	 return r[0];
}*/

 //随机播放一个视频的初始化工作        
window.initRandPlay=function (){    
    //  Singleloop  '单曲循环' :  '连播 ' 的状态码
	window.loopworld.Singleloop =false
	//设置当前的视频是否播放结束
	window.loopworld.ended = false
	//视频自动切换功能
	loopworld()	
	window.VideoArray=__getVideoArray();
	console.log(VideoArray);
	//打乱数组
	window.VideoArrayShuffle=VideoArray.__$shuffle$__();
	window.aList = window.VideoArrayShuffle.__$clone$__()
}